//
//  OrderListVC.m
//  同盟圈
//
//  Created by 洛水寒 on 16/4/19.
//  Copyright © 2016年 ym. All rights reserved.
//
//
//#import "MyStorage.h"
//#import "RefundApplyForVC.h"
//#import "ChoosePayVC.h"
//#import "RefundStausWaitViewController.h"
//#import "RefundSuccesViewController.h"
//#import "RefundHandleViewController.h"
//#import "RefundDetailViewController.h"
//#import "WaitRefundViewController.h"
//#import "RefundChooseVC.h"
#import "OrderListFooterView.h"
//#import "LogisticsVC.h"
//#import "DYTradersPassword.h"
//#import "AffirmPaymentVC.h"
#import "OrderM.h"
#import "MyMcqView.h"
#import "OrderListVC.h"
#import "NetWorkTools.h"
#import "ReadLoginData.h"

#import "ZhiFuViewController.h"
#import "SVProgressHUD.h"
#import "orderListCell.h"
#import "orderDetailViewController.h"
#import "MBProgressHUD.h"

@interface OrderListVC ()<UITableViewDelegate,UITableViewDataSource>
{
    NSString *_userId;
    UINib * nibContent;
    int currentPage;
    BOOL isLoading;
    BOOL isLastPage;
    BOOL isrefrsh;
    OrderM *orderSe;
    NSInteger index;
}
@property(nonatomic, strong) NSMutableArray *orderlist;
@property(nonatomic, strong) NSMutableArray *goodlist;
@property(nonatomic, strong) NSString *orderId;


@property (nonatomic,strong) NSArray *OrderArray;
@end


@implementation OrderListVC

- (id)initWithUserId:(NSString *)userId orderStatus:(int)orderStatus
{
    self = [self initWithTitle:nil userId:userId orderStatus:orderStatus];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (id)initWithTitle:(NSString *)title userId:(NSString *)userId orderStatus:(int)orderStatus
{
    if (self = [super init]) {
        self.title = title;//
        self.rootViewController = self;
        
        _userId = userId;
        _orderStatus = orderStatus;
        currentPage = 1;
        NSLog(@"我的订单----id %@  st %d",_userId,_orderStatus);
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    _tableView= [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT-60-45)style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorColor = [UIColor clearColor];
    _tableView.showsVerticalScrollIndicator = NO;//去掉滑动竖条
    [self.view addSubview:_tableView];
//    if (_userId) {
//    [self getOrderList:_userId status:_orderStatus page:1];
//    [self refreshPage];
//    }
    
    [SVProgressHUD show];
    //请求
    [self orderDataSource:[NSString stringWithFormat:@"%d" ,_orderStatus]];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(ReloadTableView) name:@"ReloadTableView" object:nil];

}

- (void)ReloadTableView {
    
    [SVProgressHUD show];
    //请求
    [self orderDataSource:[NSString stringWithFormat:@"%d" ,_orderStatus]];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    //注册通知
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(tongzhi:) name:@"tktongzhi" object:nil];
    
    //默认获取全部订单
   

}
-(void)tongzhi:(NSNotification *)text
{
  [self changeRefundValue:YES];
  [[NSNotificationCenter defaultCenter] removeObserver:text name:@"tktongzhi" object:self];

}
//区头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}
//区尾高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
   
     return 10;
}
//行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
     return 220;
}
//区数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.OrderArray.count;
}
//行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}



//}
//重用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    static NSString *identifier= @"orderListCell";
    orderListCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
    
    if (cell==nil) {
        cell = [[[NSBundle mainBundle]loadNibNamed:@"orderListCell" owner:nil options:nil] lastObject];
        cell.selectionStyle =  UITableViewCellSelectionStyleNone;
        
    }

    NSDictionary *dict = self.OrderArray[indexPath.section];
    
    NSString *URLString = @"http://120.76.162.124:8083";
    
    NSString *PicString = [URLString stringByAppendingString:dict[@"PictureURL"]];
    
    [cell.pruductImage sd_setImageWithURL:[NSURL URLWithString:PicString]placeholderImage:[UIImage imageNamed:@"dress.png"]];
    
    //商品名称
    cell.pruductName.text = [NSString stringWithFormat:@"商品名称:%@",dict[@"ProductName"]];
    //商品规格
    cell.pruductGuige.text = [NSString stringWithFormat:@"%@",dict[@"NormsNames"]];//规格
    //商品价格
    cell.pruductPrice.text = [NSString stringWithFormat:@"¥%@",dict[@"SellPrice"]];
     //商品数量
    cell.pruductNum.text = [NSString stringWithFormat:@"x%@",dict[@"Count"]];
    //商铺名字
    cell.storeName.text = [NSString stringWithFormat:@"%@",dict[@"MerchantName"]];
    
    //共计
    CGFloat total= [dict[@"SellPrice"] floatValue] * [dict[@"Count"] floatValue];
    cell.pruductPlus.text = [NSString stringWithFormat:@"共%@件商品 合计: ¥%.2f(含运费¥0.00)",dict[@"Count"],total];
    
    
    
    //button
    if ([dict[@"PayStatus"] isEqual:@(1)]) {
        
        //状态
        cell.stuasLabel.text = @"交易完成";
        
        [cell.pruductBtn setTitle:@"已付款" forState:UIControlStateNormal];
        [cell.pruductBtn setBackgroundColor:COLOR(249, 211, 66, 1)];
        [cell.pruductBtn.layer setMasksToBounds:YES];
        [cell.pruductBtn.layer setCornerRadius:3.0]; //设置矩圆角半径
        [cell.pruductBtn.layer setBorderColor:ZTH_Z_CORLOR.CGColor];//边框颜色
        [cell.pruductBtn setTitleColor:ZTH_Z_CORLOR forState:UIControlStateNormal];
        
        cell.cancelBtn.hidden = YES;
        
    }else{
      
        cell.stuasLabel.text = @"等待买家付款";
        
        [cell.pruductBtn setTitle:@"立即支付" forState:UIControlStateNormal];
        [cell.pruductBtn setBackgroundColor:COLOR(249, 211, 66, 1)];
        [cell.pruductBtn.layer setMasksToBounds:YES];
        [cell.pruductBtn.layer setCornerRadius:3.0]; //设置矩圆角半径
        [cell.pruductBtn.layer setBorderColor:ZTH_Z_CORLOR.CGColor];//边框颜色
        [cell.pruductBtn setTitleColor:ZTH_Z_CORLOR forState:UIControlStateNormal];
        [cell.pruductBtn addTarget:self action:@selector(rightAwayPayClick:) forControlEvents:UIControlEventTouchUpInside];
        
        cell.cancelBtn.hidden = NO;
        [cell.cancelBtn setTitle:@"取消订单" forState:UIControlStateNormal];
        [cell.cancelBtn setBackgroundColor:COLOR(249, 211, 66, 1)];
        [cell.cancelBtn.layer setMasksToBounds:YES];
        [cell.cancelBtn.layer setCornerRadius:3.0]; //设置矩圆角半径
        [cell.cancelBtn.layer setBorderColor:ZTH_Z_CORLOR.CGColor];//边框颜色
        [cell.cancelBtn setTitleColor:ZTH_Z_CORLOR forState:UIControlStateNormal];
        [cell.cancelBtn addTarget:self action:@selector(didCancelBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    

    return cell;
}


#pragma mark >>>>>>>>>>>支付
- (void)rightAwayPayClick:(UIButton *)button
{
    orderListCell * cell = (orderListCell *)[[button superview] superview];
    NSIndexPath *path = [self.tableView indexPathForCell:cell];
    
    ZhiFuViewController *payVc = [[ZhiFuViewController alloc] init];
    //    Count Count OrderNO
    NSDictionary *dict = self.OrderArray[path.section];
   
  
    
    if ([dict[@"Postion"] floatValue] == 2) {
        payVc.str = @"兑换";
        payVc.BuyQuan = @"购物券";  
        payVc.allPrice = [dict[@"NeedCardNum"] floatValue] * [dict[@"Count"] floatValue];
    }else{
        payVc.allPrice = [dict[@"SellPrice"] floatValue] * [dict[@"Count"] floatValue];
    }
    
    payVc.orderArray = [NSMutableArray arrayWithObject:dict[@"OrderNO"]];
    [self.rootViewController.navigationController pushViewController:payVc animated:YES];
}

- (void)didCancelBtn:(UIButton *)btn {
    /*
     ri.MenthodName = "ORDERCANCEL";
     uu.UserId = "7247";
     uu.OrderNum = "TTJB20160612224736";
     
     */
    NSLog(@"...%@", self.OrderArray);
    
    
    NSDictionary *dic = [ReadLoginData readLoginData];
    
    NSString *userId = [dic objectForKey:@"Number"];
    
    orderListCell * cell = (orderListCell *)[[btn superview] superview];
    NSIndexPath *path = [self.tableView indexPathForCell:cell];
    
    NSDictionary *dict = @{
                           @"UserId":userId,
                           @"OrderNum":self.OrderArray[path.section][@"OrderNumber"]
                           };
    [[NetWorkTools sharedNetWorkTools] objectWithURLDict:dict AndMenthodName:@"ORDERCANCEL" completeBlock:^(id object) {
        
        NSLog(@"%@", object);
        
        [[NSNotificationCenter defaultCenter] postNotificationName:@"CancelDingDan" object:nil userInfo:@{@"Message":object[@"Message"]}];
        
        [SVProgressHUD show];
        //请求
        [self orderDataSource:[NSString stringWithFormat:@"%d" ,_orderStatus]];
        
    }];
    
}



#pragma mark >>>>>>>>>>> 点击cell
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.rootViewController.hidesBottomBarWhenPushed=YES;

    orderDetailViewController *orderDetailsVC = [[orderDetailViewController alloc]initWithOrderId:self.OrderArray[indexPath.section] userId:@"" orderStatus:_orderStatus];
    
    [self.rootViewController.navigationController pushViewController:orderDetailsVC animated:YES];
    
}

//tabBar 隐藏
- (void)pushForm:(UINavigationController *)pushForm pushToAndHidden:(UIViewController *)pushToVC
{
    [pushToVC setHidesBottomBarWhenPushed:YES];
    [pushForm pushViewController:pushToVC animated:YES];
    
}


//区头
-(void)tableViewHeaderView:(UIView *)bgView withShopName:(NSString *)nameString withGoodsState:(NSString *)stateString
{
    UILabel *linLab = [EBUtility labfrome:CGRectMake(0, 0,SCREEN_WIDTH, 8) andText:nil andColor:nil andView:bgView];
    linLab.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UIImageView *logImg = [EBUtility imgfrome:CGRectMake(10, 15+8, 20, 20) andImg:[UIImage imageNamed:@"dd-1"] andView:bgView];
    logImg.contentMode = UIViewContentModeScaleAspectFit; //等比例缩放
    UILabel *shopNameLab = [EBUtility labfrome:CGRectMake(40, 0+8, 150, 50) andText:nameString andColor:[EBUtility colorWithHexString:@"#666666" alpha:1] andView:bgView];
    shopNameLab.textAlignment = NSTextAlignmentLeft;
     UILabel *stateLab = [EBUtility labfrome:CGRectMake(SCREEN_WIDTH-120, 0+8, 110, 50) andText:stateString andColor:[UIColor orangeColor] andView:bgView];
    stateLab.textAlignment = NSTextAlignmentRight;
}


//区尾
-(void)tableViewFooterView:(UIView *)bgView withBtn:(NSArray *)btnArray withSection:(NSInteger)sectionNum
{
    for (int i =0; i<btnArray.count; i++)
    {
        SectionBtn *btn= [EBUtility  sbtnfrome:CGRectMake(SCREEN_WIDTH-90-90*i,9.5,80, 30) andText:[btnArray objectAtIndex:i] andColor:[UIColor blackColor] andimg:nil andView:bgView];
        btn.tag = i;
        btn.backgroundColor = [UIColor whiteColor];
        btn.sectionNum = sectionNum;
        [btn addTarget:self action:@selector(btnClcik:) forControlEvents:UIControlEventTouchUpInside];
        [bgView addSubview:btn];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
        if (i ==0)
        {
            btn.backgroundColor = ZT_CORLOR;
            [btn.layer setMasksToBounds:YES];
            [btn.layer setCornerRadius:3.0]; //设置矩圆角半径
            [btn setTitleColor:ZTH_Z_CORLOR forState:UIControlStateNormal];
            
        }else
        {
            [btn.layer setMasksToBounds:YES];
            [btn.layer setCornerRadius:3.0]; //设置矩圆角半径
            [btn.layer setBorderWidth:1.0];   //边框宽度
            [btn.layer setBorderColor:ZTH_Z_CORLOR.CGColor];//边框颜色
            [btn setTitleColor:ZTH_Z_CORLOR forState:UIControlStateNormal];

        }
        
    }

}
//总计
-(void)footerViewAmount:(UILabel *)lab withOrder:(OrderM *)order withNum:(int)num
{
     lab.text = [NSString stringWithFormat:@"共%lu件商品 合计¥%.2f(含运费¥%.2f)",(unsigned long)num,order.amount,0.00];
}

-(void)btnClcik:(SectionBtn *)btn
{
    NSLog(@"状态%d 第%ld个按钮",_orderStatus,(long)btn.tag);
    

    
//    OrderM *orders = [self.orderlist objectAtIndex:btn.sectionNum];
 
//    orderSe = orders;
//    
//    switch (_orderStatus) {
//        case 1:
//        {
//            switch (btn.tag) {
//                case 0:
//                    
//                {
//                    //立即支付
//                    [self didPayOrder:orderSe];
//                }
//                    break;
//                case 1:
//                {
//                    //取消订单
//                    [self didCancelOrder:orderSe];
//                }
//                    break;
//                default:
//                    break;
//            }
//        }
//            break;
//        case 2:
//        {
//            switch (btn.tag) {
//                case 0:
//                {
//                    //提醒发货
//                    [EBUtility prompt:@"什么鬼!!!" with:self];
//                }
//                    break;
//                case 1:
//                {
//                    NSArray *array = [[NSArray alloc]init];
//                    array = [self.goodlist objectAtIndex:btn.sectionNum];
//                    //申请退款
//                    [self didApplyRefundOrder:orderSe goodlist:array];
//                }
//                    break;
//                default:
//                    break;
//            }
//
//        }
//            break;
//        case 3:
//        {
//            switch (btn.tag) {
//                case 0:
//                {
//                    //确认收货
//                    [self didConfirmOrder:orderSe];
//                }
//                    break;
//                case 1:
//                {
//                    //查看物流
//                    [self didQueryExpressOrder:orderSe];
//                }
//                    break;
//                case 2:
//                {
//                    NSArray *array = [[NSArray alloc]init];
//                    array = [self.goodlist objectAtIndex:btn.sectionNum];
//                    //申请退款
//                    [self didApplyRefundOrder:orderSe goodlist:array];
//                }
//                    break;
//                default:
//                    break;
//            }
//
//        }
//            break;
//        case 4:
//        {
//            switch (btn.tag) {
//                case 0:
//                {
//                    //查看物流
//                     [self didQueryExpressOrder:orderSe];
//                }
//                    break;
//                case 1:
//                {
//                    //删除订单
//                    [self didDeleteOrder:orderSe];
//                }
//                    break;
//                default:
//                    break;
//            }
//
//        }
//            break;
//        case 5:
//        {
//            switch (btn.tag) {
//                case 0:
//                {
//                    
//                    if (orderSe.distribution_status == 1)
//                    {//已发货
//                        
//                        if(orderSe.refund == 1){//退货申请中
//                            [self refundApplyingOrder:orderSe];
//                            
//                        }else if (orderSe.refund == 2){//等待退货
//                            if (orderSe.self_send == 1) {//1管家上门提取
//                               
//                                [self waitRefundSQOrder:orderSe];
//                            }else{//物流退货
//                                
//                                [self waitRefundOrder:orderSe];
//                            }
//                        }else if (orderSe.refund == 3){//商家确认中
//                            
//                           
//                            [self merchantConfirmOrder:orderSe];
//                        }else if (orderSe.refund == 5){//退款完成
//                            
//                            
//                             [self refundSuccessOrder:orderSe];
//                        }
//                    }else  {//未发货 if (self.order.distribution_status == 1)
//                        if(orderSe.refund == 1){//退款申请中
//                            
//                            
//                            [self refundApplyingOrder:orderSe];
//                            
//                        }else if(orderSe.refund == 3){
//                            
//                        }
//                        else if(orderSe.refund == 5){//退款完成
//                            
//                              [self refundSuccessOrder:orderSe];
//                        }
//                        
//                    }
//                }
//                    break;
//              
//                default:
//                    break;
//            }
//
//        }
//            break;
//        default:
//            break;
//    }
//    
}
- (void)waitRefundSQOrder:(OrderM *)order//等待退货 上门提取
{
    self.rootViewController.hidesBottomBarWhenPushed=YES;
    if (_userId && order.order_id) {
//        WaitRefundViewController * viewController = [[WaitRefundViewController alloc] init];
//        viewController.userId = _userId;
//        viewController.orderId = order.order_id;
//        viewController.distribution_status = order.distribution_status;
//        
//        [self.rootViewController.navigationController pushViewController:viewController animated:YES];
      
    }
}


//退货申请中
- (void)refundApplyingOrder:(OrderM *)order;
{
    self.rootViewController.hidesBottomBarWhenPushed=YES;
    if (_userId && order.order_id) {
//        RefundHandleViewController  * viewController = [[RefundHandleViewController alloc] init];
//        viewController.userId = _userId;
//        viewController.orderId = order.order_id;
//        viewController.real_amount = order.real_amount;
//        viewController.distribution_status = order.distribution_status;
//        [self.rootViewController.navigationController pushViewController:viewController animated:YES];
        
    }
}

- (void)waitRefundOrder:(OrderM *)order;//等待退货
{
    self.rootViewController.hidesBottomBarWhenPushed=YES;
    if (_userId && order.order_id) {
//        RefundDetailViewController * viewController = [[RefundDetailViewController alloc] init];
//        viewController.userId = _userId;
//        viewController.orderId = order.order_id;
//        viewController.distribution_status = order.distribution_status;
//        
//        [self.rootViewController.navigationController pushViewController:viewController animated:YES];
        
    }
}


- (void)merchantConfirmOrder:(OrderM *)order;//商家确认中
{
    self.rootViewController.hidesBottomBarWhenPushed=YES;
    if (_userId && order.order_id) {
//        RefundStausWaitViewController  * viewController = [[RefundStausWaitViewController alloc] init];
//        viewController.userId = _userId;
//        viewController.orderId = order.order_id;
//        viewController.distribution_status = order.distribution_status;
//        
//        [self.rootViewController.navigationController pushViewController:viewController animated:YES];
     
    }
}

- (void)refundSuccessOrder:(OrderM *)order;//退款成功
{
    self.rootViewController.hidesBottomBarWhenPushed=YES;
    if (_userId && order.order_id) {
//        RefundSuccesViewController  * viewController = [[RefundSuccesViewController alloc] init];
//        viewController.userId = _userId;
//        viewController.orderId = order.order_id;
//        viewController.distribution_status = order.distribution_status;
//        
//        [self.rootViewController.navigationController pushViewController:viewController animated:YES];
     
    }
}


// 取消订单
- (void)didCancelOrder:(OrderM *)order
{
    self.orderId = order.order_id;
    NSMutableArray *arr = [NSMutableArray arrayWithObjects:@"我不想买了",@"信息核对错误",@"其他", nil];
    NSString *string = @"确认取消订单(请选择取消原因)";
    [self popupView:string btntitleArray:arr];
 

}
// 立即支付
- (void)didPayOrder:(OrderM *)order
{
      self.rootViewController.hidesBottomBarWhenPushed=YES;
//    ChoosePayVC *choosePayVC = [[ChoosePayVC alloc]init];
//    [ self.rootViewController.navigationController pushViewController:choosePayVC animated:YES];
    //  self.rootViewController.hidesBottomBarWhenPushed=NO;
}
// 删除订单
- (void)didDeleteOrder:(OrderM *)order
{
    self.orderId = order.order_id;
    NSString *string = @"删除订单后将无法查询该订单的所有信息";
    [self popupView:string btntitleArray:nil];
}
// 查看物流
- (void)didQueryExpressOrder:(OrderM *)order
{
//    self.rootViewController.hidesBottomBarWhenPushed=YES;
//    LogisticsVC *logisticsVC = [[LogisticsVC alloc]initWithUserId:_userId orderId:order.order_id store:order.shop_id];
//    [ self.rootViewController.navigationController pushViewController:logisticsVC animated:YES];

}
// 申请退款
- (void)didApplyRefundOrder:(OrderM *)order goodlist:(NSArray *)goodlist
{
   
//    self.rootViewController.hidesBottomBarWhenPushed=YES;
//    RefundChooseVC *refundChooseVC = [[RefundChooseVC alloc]initWithUserId:_userId orderStatus:_orderStatus WithOrder:order];
//    refundChooseVC.goodslist = goodlist;
//    
//    [self.rootViewController.navigationController pushViewController:refundChooseVC animated:YES];

}
// 评价订单
- (void)didEvaluateOrder:(OrderM *)order goodlist:(NSArray *)goodlist
{
    
}
// 确认收货
- (void)didConfirmOrder:(OrderM *)orders
{
//    DYTradersPassword *passwordView = [[DYTradersPassword alloc]init];
//    
//    [passwordView.btn setTitle:@"取消" forState:UIControlStateNormal];
//    [passwordView.btn2 setTitle:@"确定" forState:UIControlStateNormal];
//    passwordView.nameTitle.text = @"确认收货";
//
//    passwordView.bankLabel.text = [NSString stringWithFormat:@"%0.2f元",orders.amount];//@"49.60元";
//    
//    //去掉￥符号
//
//    passwordView.moneyLabel.text = orders.goodsName;
//    passwordView.promptLab.text = @"请收到货后,再进行确认收货!否则您可能钱货两空";
//
//    
//    passwordView.bankImg.image ;
//    passwordView.clickedBtnIndexBlock = ^(NSInteger index)
//    {
//        if (index == 0)
//        {
//            
//            NSLog(@"点了取消");
//        }
//        else{
//            //需要验证支付密码
//            [self confirmOrder:_userId userId:orders.order_id];
//            
//        }
//    };
//    
//    [passwordView show];
    

    self.orderId = orders.order_id;
    NSString *string = @"是否确认收到货物?";
    [self popupView:string btntitleArray:nil];
}


-(void)popupView:(NSString *)titleString btntitleArray:(NSMutableArray *)array
{
//    
//    MyMcqView *alertView = [[MyMcqView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) titleArray:array];
//    if (_orderStatus == 4) {
//        alertView.lab.textAlignment = NSTextAlignmentCenter;
//        alertView.lab.font = [UIFont systemFontOfSize:14];
//    }
//    if (_orderStatus == 3) {
//        alertView.lab.textAlignment = NSTextAlignmentCenter;
//        alertView.lab.font = [UIFont systemFontOfSize:14];
//    }
//    alertView.lab.text = titleString;
//    
//    if (_orderStatus ==1) {
//        alertView.prompt = @"请选择取消原因";
//    }
//    if (_orderStatus ==2 ||_orderStatus ==3) {
//        alertView.prompt = @"请选择退款原因";
//    }
//    alertView.clickedBtnIndexBlock = ^(NSInteger index)
//    {
//        
//   
//       
//        switch (_orderStatus) {
//            case 1:
//            {
//                //取消
//                [self cancelOrder:_userId orderId:self.orderId reason:[NSString stringWithFormat:@"%@",[array objectAtIndex: index]]];
//            }
//                break;
//            case 4:
//            {
//                //删除
//                   [self deleteOrder:_userId orderId:self.orderId];
//            }
//                break;
//            case 3:
//            {
//                //确认收货
//                 [self confirmOrder:_userId userId:self.orderId];
//            }
//                break;
//                
//            default:
//                break;
//        }
//        
//    };
//    [alertView show];
    
}
//详情页的回调
- (void)changeValue:(BOOL)value
{
    if (value == YES) {
        [self.tableView.mj_header beginRefreshing];
        isrefrsh = YES;
    }
   
}
//退款页回调
- (void)changeRefundValue:(BOOL)value
{
    if (value == YES) {
        [self.tableView.mj_header beginRefreshing];
        isrefrsh = YES;
    }
}


//MJ刷新
-(void)refreshPage
{
    //下拉刷新
    self.tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^
                                {
                                  
                                    if ([NSString stringWithFormat:@"%d",_orderStatus] !=nil) {
                                        [self getOrderList:_userId status:_orderStatus page:1];
                                    }
                                    
                                    [self.tableView.mj_header endRefreshing];
                                }];
    
    //上拉加载
    self.tableView.mj_footer = [MJRefreshBackNormalFooter footerWithRefreshingBlock:^{
        
        if (isLastPage) {
            [EBUtility prompt:@"已加载至最后一页" with:self];
            [self.tableView.mj_footer endRefreshing];
            return;
        }
        if ([NSString stringWithFormat:@"%d",_orderStatus] !=nil) {
           
           
            [self getOrderList:_userId status:_orderStatus page:currentPage+1];
        }

        [self.tableView.mj_footer endRefreshing];
    }];
    
}
#pragma mark ---订单请求
// 订单列表
- (void)getOrderList:(NSString *)userId status:(int)status page:(int)page
{
    
}


// 取消订单
- (void)cancelOrder:(NSString *)userId orderId:(NSString *)orderId reason:(NSString *)reason
{
   
}

// 删除订单
- (void)deleteOrder:(NSString *)userId orderId:(NSString *)orderId
{
 
  
}

// 订单确认收货
- (void)confirmOrder:(NSString *)orderId userId:(NSString *)userId
{
  
}

#warning 记录
//发送
//0 全部 1 未 2 已

//请求
//0 未 1已
#pragma mark >>>>>>>>> 获取订单
- (void)orderDataSource:(NSString *)PayStatusIndex{
    
    NSDictionary *dict = [ReadLoginData readLoginData];
    
    NSDictionary *params = @{
                             @"UserId":[dict objectForKey:@"Number"],
                             @"PayStatus":PayStatusIndex
                             
                             };
    
    [[NetWorkTools sharedNetWorkTools] objectWithURLDict:params AndMenthodName:@"QUEYORDERLIST" completeBlock:^(id object) {

        NSString *string = [object objectForKey:@"BackData"];
       self.OrderArray = [NetWorkTools arrayWithJsonString:string];
        NSLog(@"%@",self.OrderArray);
        [self.tableView reloadData];
        
        [SVProgressHUD dismiss];

    }];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [SVProgressHUD dismiss];
}



@end
